package demo;
/**
 * 邢帅教育
 * <p>
 * 本源代码由数据中心及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2018. xsteach.com all rights reserved.
 */

import demo.component.CupComponent;
import demo.component.DemoComponent;
import demo.configuration.DemoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;

/**
 * @author maikec
 * @date 2018/9/12
 */
public class DemoApplication {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext( );
        ConfigurableEnvironment environment = new StandardEnvironment();
        environment.setActiveProfiles( "dev" );
        ((AnnotationConfigApplicationContext) applicationContext).setEnvironment( environment  );
        ((AnnotationConfigApplicationContext) applicationContext).register( DemoConfiguration.class );

        ((AnnotationConfigApplicationContext) applicationContext).refresh();
        System.out.println( applicationContext.getBean( DemoComponent.class ).introduce() );

        applicationContext.getBean( DemoComponent.class).bye();

        System.out.println( applicationContext.getBean( CupComponent.class ).introduceDemoComponent() );
        ((AnnotationConfigApplicationContext) applicationContext).close();
    }
}
